package com.codeti.core.wordcount;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author: zhenzhong.wang@honeywell.com
 * @date: 2019/10/8 3:06 PM
 */
public class WordCountMain {

  public static void main(String[] args) throws Exception {
    Configuration config = new Configuration();

    Job job = Job.getInstance(config);

    // 指定job的任务入口
    job.setJarByClass(WordCountMain.class);

    // 设置job的mapper
    job.setMapperClass(WordCountMapper.class);
    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(LongWritable.class);

    // 设置job的reduce
    job.setReducerClass(WordCountReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(LongWritable.class);

    // 指定任务的输入输出格式
    FileInputFormat.setInputPaths(job, new Path(args[0]));
    FileOutputFormat.setOutputPath(job, new Path(args[1]));

    // true表示打印日志
    job.waitForCompletion(true);
  }

}
